package com.hibernate.springTest;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.hibernate.domain.Address;
import com.hibernate.domain.Event;
import com.hibernate.domain.Location;
import com.hibernate.test.EventLoader;
import com.hibernate.utils.HibernateFactory;

public class TestHibernateTemplate {
	static Session session = null;
	static Transaction tx = null;
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HibernateFactory.buildSessionFactory();
	
	Event e1 = new Event();
	e1.setName("xxx454646");
	e1.setStartDate(EventLoader.createDate(2009, 01, 02));
	e1.setDuration(200);
	Location location = new Location();
	 location.setName("myHome");
	Address address = new Address();
	 address.setCity("shangrao");
	 address.setState("jiangxi");
	 address.setStreetAddress("76 road");
	 address.setZipcode("334100");
	location.setAddress(address);

	create(e1);

	}
	protected static void create(Event event)
	{
	
		startOperation();
		
		SessionFactory sf = HibernateFactory.getSf();
		HibernateTemplate template = new HibernateTemplate(sf);
		template.save(event);
	}
	private static void startOperation() {
		session = HibernateFactory.openSession();
		tx = session.beginTransaction();
	}
	

}
